import { request } from '@/common/ajax'

// function removeEmpty(data) {
//     let obj = {};
//     for (let p in data) {
//         if (data.hasOwnProperty(p) && data[p] !== '' && data[p] !== undefined) {
//             obj[p] = data[p]
//         }
//     }
//     return obj;
// }

export function uploadFile(data) {
  // let url = '';
  // aliOssUpload(url,success,error);
}

// 登录
export function login(data, success, error) {
  return request('auth/login', 'post', data, success, error)
}
export function logout(data, success, error) {
  return request('auth/logout', 'post', {}, success, error)
}
// 获取登录信息
export function loginInfo(success, error) {
  return request('auth/info', 'get', {}, success, error)
}

// 修改密码
export function changePwd(data, success, error) {
  return request('auth/change-password ', 'patch', data, success, error)
}

// 刷新全局缓存
export function refreshCache(success, error) {
  return request('refresh', 'get', {}, success, error)
}

// 管理员账号
export function getAccount(data, success, error) {
  return request('admin/lists', 'get', data, success, error)
}

export function saveAccount(data, success, error) {
  return request('admin/save', 'post', data, success, error)
}

export function accountStatus(data, success, error) {
  return request('admin/status', 'post', data, success, error)
}

// 用户
export function userLists(data, success, error) {
  return request('user-sys/user', 'get', data, success, error)
}
export function userInfo(user_id, success, error) {
  return request('user-sys/user/' + user_id, 'get', {}, success, error)
}

export function addUser(data, success, error) {
  return request('user-sys/user', 'post', data, success, error)
}

export function editUser(user_id, data, success, error) {
  return request('user-sys/user/' + user_id, 'post', data, success, error)
}

export function userChStatus(user_id, success, error) {
  return request(
    'user-sys/user/' + user_id + '/set-status',
    'patch',
    {},
    success,
    error
  )
}
export function userResetPwd(user_id, success, error) {
  return request(
    'user-sys/user/' + user_id + '/reset-password',
    'patch',
    {},
    success,
    error
  )
}
export function userPermission(id, data, success, error) {
  return request(
    'user-sys/user/' + id + '/allot-permissions',
    'post',
    { permissions: data },
    success,
    error
  )
}
export function userRole(id, data, success, error) {
  return request(
    'user-sys/user/' + id + '/allot-roles',
    'post',
    { roles: data },
    success,
    error
  )
}
//角色
export function createRole(data, success, error) {
  return request('user-sys/role ', 'post', data, success, error)
}
export function roleList(data, success, error) {
  return request('user-sys/role', 'get', data, success, error)
}
export function getRole(id, success, error) {
  return request('user-sys/role/' + id, 'get', {}, success, error)
}

export function roleSave(id, data, success, error) {
  return request('user-sys/role/' + id, 'post', data, success, error)
}

export function rolePermission(id, data, success, error) {
  return request(
    'user-sys/role/' + id + '/allot-permissions',
    'post',
    { permissions: data },
    success,
    error
  )
}

export function rolePostDel(role_id, success, error) {
  return request('user-sys/role/' + role_id, 'delete', {}, success, error)
}
//权限
export function permissionTree(success, error) {
  return request('user-sys/permission/tree', 'get', {}, success, error)
}
export function fetchPermission(id, success, error) {
  return request('user-sys/permission/' + id, 'get', {}, success, error)
}
export function addPermission(data, success, error) {
  return request('user-sys/permission', 'post', data, success, error)
}
export function editPermission(id, data, success, error) {
  return request('user-sys/permission/' + id, 'post', data, success, error)
}
export function deletePermission(id, success, error) {
  return request('user-sys/permission/' + id, 'delete', {}, success, error)
}
//菜单组
export function menuGroupLists(data, success, error) {
  return request('user-sys/menu/menu-group', 'get', data, success, error)
}
export function menuGroupSetStatus(id, success, error) {
  return request(
    'user-sys/menu/menu-group/' + id + '/set-status',
    'patch',
    {},
    success,
    error
  )
}
export function fetchMenuGroup(id, success, error) {
  return request('user-sys/menu/menu-group/' + id, 'get', {}, success, error)
}
export function addMenuGroup(data, success, error) {
  return request('user-sys/menu/menu-group', 'post', data, success, error)
}
export function updateMenuGroup(id, data, success, error) {
  return request('user-sys/menu/menu-group/' + id, 'post', data, success, error)
}
export function deleteMenuGroup(id, success, error) {
  return request('user-sys/menu/menu-group/' + id, 'delete', {}, success, error)
}
//菜单
export function treeMenu(gid, success, error) {
  return request('user-sys/menu', 'get', { gid }, success, error)
}
export function menuSelect(data, success, error) {
  return request('user-sys/menu/menu-select', 'get', data, success, error)
}
export function fetchMenu(id, success, error) {
  return request('user-sys/menu/' + id, 'get', {}, success, error)
}
export function addMenu(data, success, error) {
  return request('user-sys/menu', 'post', data, success, error)
}
export function editMenu(id, data, success, error) {
  return request('user-sys/menu/' + id, 'post', data, success, error)
}
export function menuSetStatus(id, success, error) {
  return request(
    'user-sys/menu/' + id + '/set-status',
    'patch',
    {},
    success,
    error
  )
}

// 反馈
export function feedbackLists(data, success, error) {
  return request('feedback/lists', 'get', data, success, error)
}

export function feedbackInfo(method, data, success, error) {
  return request('feedback/info', method, data, success, error)
}

// 配置
export function configLists(data, success, error) {
  return request('config/lists', 'get', data, success, error)
}

export function configValue(data, success, error) {
  return request('config/Value', 'put', data, success, error)
}
